<?php


namespace App\Exception\Handler;


use Hyperf\ExceptionHandler\ExceptionHandler;
use Hyperf\Validation\ValidationException;
use Psr\Http\Message\ResponseInterface;
use Throwable;

class FromValidateExceptionHandler extends ExceptionHandler
{
    public function handle(Throwable $throwable, ResponseInterface $response): ResponseInterface
    {
        if ($throwable instanceof ValidationException) {
            $this->stopPropagation();
            return response()->error(400, $throwable->validator->errors()->first());
        }

        return $response;
    }


    public function isValid(Throwable $throwable): bool
    {
        return true;
    }
}